package com.explore.demo.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * @author gaolaiann
 */
@Data
@AllArgsConstructor
@Getter
@Setter
@Accessors(chain = true)
public class ServerResponse<T> {

    private Integer code;

    private String message;

    private T data;

    private ServerResponse(){};

    public ServerResponse(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public ServerResponse(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public ServerResponse( String message, Integer code,T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }


    public static <T> ServerResponse<T> createdBySuccess(T data){
        return new ServerResponse<T>(ResultCode.SUCCESS.getCode(), data);
    }

    public static <T> ServerResponse<T> createBySuccessMessage(String message,T data) {
        return new ServerResponse<T>(ResultCode.SUCCESS.getCode(), message, data);
    }

    public static <T> ServerResponse<T> createBySuccessMessage(String message) {
        return new ServerResponse<T>(ResultCode.SUCCESS.getCode(), message);
    }

    public static <T> ServerResponse<T> createBySuccessMessage(String message,Integer code,T data) {
        return new ServerResponse<T>(message, code, data);
    }

    public static <T> ServerResponse<T> createByErrorMessage(String message,Integer code,T data) {
        return new ServerResponse<T>(message, code, data);
    }

    public static <T> ServerResponse<T> createByError(T data){
        return new ServerResponse<T>(ResultCode.ERROR.getCode(), ResultCode.ERROR.getDescription(), data);
    }

    public static <T> ServerResponse<T> createByErrorMessage(String errorMessage){
        return new ServerResponse<T>(ResultCode.ERROR.getCode(), errorMessage);
    }

}
